package com.lhl.fw.db.biz.domain.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import com.lhl.fw.db.entity.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Company extends BaseEntity<String> {
	
	private String name;
	@OneToMany(mappedBy="company",cascade=CascadeType.ALL)
	@OrderBy(value="id ASC")
	private Set<Employee> employees = new HashSet<Employee>();

	public void addEmployee(Employee employee) {
		this.employees.add(employee);
		employee.setCompany(this);
	}
	
	public void removeEmployee(Employee employee) {
		if(this.employees.contains(employee)) {
			this.employees.remove(employee);
		}
	}
}
